package ercahshu

import "fmt"

func binaryTreePaths(root *TreeNode) []string {
	// 就是前序遍历，稍微有点回溯的思想
	ans := make([]string, 0)
	var dfs func(node *TreeNode, s string)
	dfs = func(node *TreeNode, s string) {
		if node == nil {
			return
		}
		s += fmt.Sprintf("%d->", node.Val)
		if node.Left == nil && node.Right == nil {
			ans = append(ans, s[:len(s)-2])
		}
		dfs(node.Left, s)
		dfs(node.Right, s)
	}
	dfs(root, "")
	return ans
}
